if ((reportData.last_rec_req_id === null) || (reportData.last_rec_req_id < rec_req.id)) {
reportData.last_rec_req_id = rec_req.id;
}
}
} finally {
if (stmt) {
try {
stmt.finalize();
} catch (ex) {
}
stmt = null;
}
}
try {
if (last_rec_action_id !== null) {
stmt = conn.createStatement("SELECT id,event_time,req_id,rec_id,client_version,action,destination,real_estate_kind,real_estate_position FROM recs_actions WHERE id > ?1");
stmt.bindInt64Parameter(0,last_rec_action_id);
} else {
stmt = conn.createStatement("SELECT id,event_time,req_id,rec_id,client_version,action,destination,real_estate_kind,real_estate_position FROM recs_actions");
var cleanupMarkerTime = now - Prefs.db_recs_acks_max_age_millis;
stmt = conn.createStatement("DELETE FROM recs_acks WHERE last_viewed_in_teaser_time < ?1 AND last_rec_received_time < ?2");
stmt.bindInt64Parameter(0,cleanupMarkerTime);
stmt.bindInt64Parameter(1,cleanupMarkerTime);
stmt.execute();
} finally {
if (stmt) {
try {
stmt.finalize();
} catch (ex) {
}
stmt = null;
}
}
} catch (ex) {
if (window.Components) {
Components.utils.reportError(ex);
}
} finally {
if (conn) {
try {
conn.close();
} catch (ex) {
}
conn = null;
}
}
},
upgradeToV0_1: function(conn,version) {
if (version != "0.1") {
throw "Unsupported version number for upgrade: " + version;
}
conn.executeSimpleSQL("CREATE TABLE IF NOT EXISTS schema_version (serial INTEGER PRIMARY KEY ASC AUTOINCREMENT, version VARCHAR(30), created_by_client VARCHAR(255), instance_id VARCHAR(36))");
conn.executeSimpleSQL("CREATE TABLE IF NOT EXISTS rec_reqs (id INTEGER PRIMARY KEY ASC AUTOINCREMENT, req_time VARCHAR(23), resp_time VARCHAR(23), req_id VARCHAR(255), client_version VARCHAR(255), cancelled INTEGER NOT NULL)");
conn.executeSimpleSQL("CREATE TABLE IF NOT EXISTS recs_followed (id INTEGER PRIMARY KEY ASC AUTOINCREMENT, event_time VARCHAR(23), req_id VARCHAR(255) NOT NULL, rec_id VARCHAR(255) NOT NULL, client_version VARCHAR(255))");
conn.executeSimpleSQL("CREATE TABLE IF NOT EXISTS reports (id INTEGER PRIMARY KEY, report_time INTEGER NOT NULL, last_rec_req_id INTEGER NULL, last_rec_followed_id INTEGER NULL)");
},
upgradeToV0_2: function(conn,version) {
if (version != "0.2") {
throw "Unsupported version number for upgrade: " + version;
}
conn.executeSimpleSQL("CREATE TABLE IF NOT EXISTS recs_acks (url VARCHAR(2047) PRIMARY KEY, last_viewed_in_teaser_time INTEGER, last_rec_received_time INTEGER NOT NULL)");
conn.executeSimpleSQL("CREATE INDEX IF NOT EXISTS recs_acks_last_viewed_in_teaser_time_idx ON recs_acks (last_viewed_in_teaser_time ASC)");
conn.executeSimpleSQL("CREATE INDEX IF NOT EXISTS recs_acks_last_rec_received_time_idx ON recs_acks (last_rec_received_time ASC)");
},
upgradeToV0_3: function(conn,version) {
if (version != "0.3") {
throw "Unsupported version number for upgrade: " + version;
}
conn.executeSimpleSQL("CREATE TABLE IF NOT EXISTS cached_rec_req_hits (id INTEGER PRIMARY KEY ASC AUTOINCREMENT, hit_time VARCHAR(23) NOT NULL, req_id VARCHAR(255), client_version VARCHAR(255))");
conn.executeSimpleSQL("CREATE TABLE IF NOT EXISTS user_events (id INTEGER PRIMARY KEY ASC AUTOINCREMENT, event_time VARCHAR(23), element VARCHAR(255) NOT NULL, event VARCHAR(255) NOT NULL, client_version VARCHAR(255), segments VARCHAR(255) DEFAULT NULL, value VARCHAR(255) DEFAULT NULL)");
// We create a new last_report table to replace the reports table. We also add a new column and rename the deprecated last_rec_followed_id
conn.executeSimpleSQL("ALTER TABLE reports RENAME TO reports_old");
conn.executeSimpleSQL("CREATE TABLE IF NOT EXISTS last_report (id INTEGER PRIMARY KEY, report_time INTEGER NOT NULL, last_rec_req_id INTEGER NULL, last_rec_action_id INTEGER NULL, last_cached_rec_req_hit_id INTEGER NULL, last_user_event_id INTEGER NULL)");
conn.executeSimpleSQL("INSERT INTO last_report (id,report_time, last_rec_req_id, last_rec_action_id, last_cached_rec_req_hit_id) SELECT 1,report_time,last_rec_req_id,last_rec_followed_id,last_cached_rec_req_hit_id FROM reports_old ORDER BY id DESC LIMIT 1");